//封装和文章相关的接口函数

import { request } from "../utils";

export interface Channel {
  id: number;
  name: string;
}

export interface PublishForm {
  title: string;
  channel_id: number;
  content: string;
  cover?: {
    type: number;
    images?: string[];
  };
  id?: string;
}

//1. 获取频道列表
export function getChannelAPI() {
  return request({
    url: "/channels",
    method: "get",
  });
}

//2.提交文章表单
export function publishArticleAPI(formData: PublishForm) {
  return request({
    url: "/mp/articles?draft=false",
    method: "post",
    data: formData,
  });
}
// 2.1更新文章提交
export function rePublishArticleAPI(formData: PublishForm) {
  return request({
    url: `/mp/articles/${formData.channel_id}?draft=false`,
    method: "put",
    data: formData,
  });
}

//3.拿文章列表
export interface ArticleType {
  comment_count: number;
  cover: {
    images: string[];
    type: number;
  };
  id: string;
  title: string;
  status: number;
  pubdate: string;
  read_count: number;
  like_count: number;
}
export function getArticleAPI(params?: any) {
  return request({
    url: "/mp/articles",
    method: "get",
    params,
  });
}

//删除文章
export function deleteArticleAPI(id: string) {
  return request({
    url: `/mp/articles/${id}`,
    method: "delete",
  });
}

//获取文章详情
export function getArticleByIdAPI(id: string) {
  return request({
    url: `/mp/articles/${id}`,
    method: "get",
  });
}
